package xiaocao.learn.java.io;

import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.regex.Pattern;

class DirFilter implements FilenameFilter {
	
	private Pattern pattern;
	
	public DirFilter(Pattern pattern) {
		this.pattern = pattern;
	}

	@Override
	public boolean accept(File dir, String name) {
		return pattern.matcher(name).matches();
	}
	
}

public class FilenameFilterExample {
	
	public static void main(String[] args) {
		File file = new File("d://test");
		//String[] list = file.list(new DirFilter(Pattern.compile("[a-z]+")));
		String[] list = file.list(new DirFilter(Pattern.compile("[0-9]+.txt")));
		Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
		for(String dirItem : list) {
			System.out.println(dirItem);
		}
	}

}
